<template>
  <div class="main">
    <div class="header">

      <div class="navbarbox">
        <div class="navbarlist">

          <!-- <div class="title">
            昌吉回族自治州机动车监管平台
          </div> -->
          <div class="hk-title title">
            昌吉回族自治州机动车监管平台
          </div>
          <div style="flex: 1; display: flex;margin-left: 70px;">
            <div class="item" :class="navListSum === index ? 'active' : ''" @click="switchPath(index, item.path)"
              v-for="(item, index) in navList" :key="index">
              <!-- <i></i> -->
              <span>{{ item.title }}</span>
            </div>
          </div>
          <div style="flex: 1;" class="item">
            <div @click="jump" class="jump">
              <i></i><span>后台管理</span>
            </div>
            <div @click="close" class="exit">
              <!-- <i></i> -->
              <span>退出</span>
            </div>
          </div>


        </div>
      </div>
    </div>
    <div class="content">
      <router-view></router-view>
    </div>
  </div>
</template>

<script>
import { logout } from "@/api/login";
import { removeToken } from '@/utils/auth'
// const basUrl = process.env.BASE_URL.replace(/\/$/, '')
const basUrl = ""

export default {
  name: 'index',
  data() {
    return {
      value: [],
      options: [
        {
          value: 'zhinan',
          label: '指南',
        },
        {
          value: 'ziyuan',
          label: '资源',
        }
      ],
      navList: [
        { title: '车辆监控', path: basUrl + '/CarScreen' },
        { title: '企业监控', path: basUrl + '/CompanyScreen' },
        { title: '统计分析', path: basUrl + '/statistical/region' },
        { title: '排放态势', path: basUrl + '/PaiFangScreen' },
        /*{title:'其他分析',path:'/'}*/
      ],
      navListSum: 0
    }
  },
  watch: {
    '$route': {
      handler: function (val, oldval) {
        // 当前先这样 todo 之后需要监听路由
        for (const k in this.navList) {
          if (val.path.indexOf(this.navList[k].path) !== -1) {
            this.navListSum = parseInt(k)
            break
          }
        }
      },
      immediate: true
    }
  },
  methods: {
    jump() {
      let url = window.location.protocol + '//' + window.location.host + '/admin/index'
      window.location.href = url
    },
    close() {
      logout().then((response) => {
        // 后端返回成功，手动处理登出
        removeToken('hezuoMJXT');
        this.$router.push('/login'); // 跳转到正常的 /login 路径
      })
    },
    switchPath(index, path) {
      if (this.$route.path.indexOf(path) === -1) {
        this.navListSum = index
        this.$router.push({ path: path })
      }
    },
    jumpYfjk() {
      /*跳转链接*/
      // location.href = 'https://kypt.taes.cn:10081/'
      window.open('https://kypt.taes.cn:10081/')
    },
    jumpht() {
      let token = storage.token_type + " " + storage.access_token;
      // window.open('http://192.168.42.2:19080/login') 
      window.open('http://192.168.42.2:19080/?redict=admin&token=' + token)
    },
    /*跳转登录页*/
    goLogin() {
      this.$router.push({ path: '/login' })
    }
  }
}
</script>

<style scoped lang="scss">
.main {
  width: 100vw;
  height: 100vh;
  overflow: hidden;

  // background: url('~@/assets/image/main-bg.png') no-repeat center;
  background-size: cover;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;

  .header {
    position: fixed;
    /* 固定定位，脱离文档流 */
    top: 0;
    /* 固定在顶部 */
    left: 0;
    /* 左侧对齐 */
    width: 100%;
    /* 占据全宽 */
    z-index: 100;
    /* 确保显示在内容上方 */
    background-color: transparent;

    /* 背景半透明，可根据需求调整 */
    .navbarbox {
      width: 100%;
      height: 70px;
      display: flex;
      align-items: center;
      justify-content: center;

      .navbarlist {
        margin-bottom: 3px;
        width: 100%;
        height: 100%;
        display: flex;
        position: relative;

        .jump {
          position: absolute;
          right: 100px;
          z-index: 1;
          font-size: 1.0vw;

          cursor: pointer;
          height: 40px;
          // display: flex;
          align-items: center;
          box-sizing: border-box;
          color: #c5dce8;
          background-size: contain;
        }

        .exit {
          position: absolute;
          right: 0;
          margin-right: 10px;
          z-index: 1;
          cursor: pointer;
          height: 40px;
          // display: flex;
          align-items: center;
          box-sizing: border-box;
          color: #c5dce8;
          background-size: contain;

          i {
            width: 20px;
            height: 20px;
            margin-right: 5px;
            display: inline-block;
            background-color: #00fff4;
            background: url("~@/assets/image/exit.svg") no-repeat center;
            background-size: cover;
          }

          span {
            display: inline-block;
            // flex: 1;
            font-size: 1.0vw;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
          }


        }

        .item {
          flex: 1;
          cursor: pointer;
          display: flex;
          align-items: center;
          box-sizing: border-box;
          background-size: contain;

          i {
            width: 30px;
            height: 30px;
            margin-right: 5px;
          }

          span {
            flex: 1;
            font-size: 1.0vw;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
            color: white;
          }

          &:nth-child(1) {
            // justify-content: flex-end;
            // flex-grow: 1;

            // i {
            //   background: url("~@/assets/image/vehicle.svg") no-repeat center;
            //   background-size: cover;
            // }
          }

          &:nth-child(2) {
            // justify-content: flex-end;
            // flex-grow: 1;

            // margin-left: 30px;

            // i {
            //   background: url("~@/assets/image/discharge.svg") no-repeat center;
            //   background-size: cover;
            // }
          }

          &:nth-child(3) {
            // flex-grow: 1;
            // justify-content: flex-start;


            // i {
            //   background: url("~@/assets/image/datav.svg") no-repeat center;
            //   background-size: cover;
            // }
          }

          &:nth-child(n+4) {
            // flex-grow: 1;


            // i {
            //   background: url("~@/assets/image/other.svg") no-repeat center;
            //   background-size: cover;
            // }
          }

        }

        .active {
          span {
            color: #00fff4;
            font-size: 1.0vw;

          }

          &:nth-child(1) {
            // i {
            //   background: url("~@/assets/image/vehicle-active.svg") no-repeat center;
            //   background-size: cover;
            // }
          }

          &:nth-child(2) {
            // i {
            //   background: url("~@/assets/image/discharge-active.svg") no-repeat center;
            //   background-size: cover;
            // }
          }

          &:nth-child(3) {
            // i {
            //   background: url("~@/assets/image/datav-.svg") no-repeat center;
            //   background-size: cover;
            // }
          }

          &:nth-child(n+4) {
            // margin-left: 30px;

            // i {
            //   background: url("~@/assets/image/other-active.svg") no-repeat center;
            //   background-size: cover;
            // }
          }
        }

        .title {
          // position: absolute;
          // top: 35px;
          // box-sizing: border-box;
          // width: 100%;
          // height: 66px;
          // line-height: 66px;
          // // background: url('~@/assets/image/title2.png') no-repeat center;
          // z-index: 0;
          // text-align: center;
          // overflow: hidden;
          // text-overflow: ellipsis;
          // white-space: nowrap;
          // font-size: 28px;
          // letter-spacing: 1px;
          // color: #ffffff;
          // box-shadow: 0px 4px 4px 0px rgba(0, 0, 0, 0.5);
          display: flex;
          width: auto;
          color: white;
          height: 100%;
          font-size: 1.9vw;
          align-items: center;
          padding: 0.3vw 0.1vw;
          -webkit-border-bottom-right-radius: 2.7rem;
          background: -webkit-gradient(linear, left bottom, left top, from(#038bff), color-stop(40%, rgba(3, 139, 255, .4)), to(rgba(3, 139, 255, 0)));
          background: linear-gradient(180deg, rgba(95, 131, 255, .6), rgba(57, 195, 255, .75));
        }
      }
    }
  }

  .content {
    height: 100%;
    width: 100%;
    flex: 1;
  }

}
</style>
